<?php

/* Load registration file. */
require_once( ABSPATH . WPINC . '/registration.php' );

/* Check if users can register. */
$registration = get_option( 'users_can_register' );

/* If user registered, input info. */
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'adduser' ) {
	$user_pass = $_POST['first_name'] . wp_generate_password(5, false, false);
	$userdata = array(
		'user_pass' => $user_pass,
		'user_login' => esc_attr( $_POST['email'] ),
		'first_name' => esc_attr( $_POST['first_name'] ),
		'last_name' => esc_attr( $_POST['last_name'] ),
		'user_email' => esc_attr( $_POST['email'] ),
	);

	$birth = $_POST['birth'];
	
	if ( !$userdata['user_login'] )
		$error = __('É obrigatório o uso de um e-mail para o cadastro.', 'frontendprofile');
	elseif ( username_exists($userdata['user_login']) )
		$error = __('Desculpe, mas este e-mail já está em uso.', 'frontendprofile');
	
	elseif ( !is_email($userdata['user_email'], true) )
		$error = __('Você precisa usar um e-mail válido.', 'frontendprofile');
	elseif ( email_exists($userdata['user_email']) )
		$error = __('Desculpe, mas este e-mail já está em uso.', 'frontendprofile');
	elseif (!$birth)
		$error = __('Desculpe, mas precisamos da sua data de nascimento.', 'frontendprofile');
	elseif ( !$userdata['first_name'] )
		$error = __('Desculpe, mas precisamos do seu primeiro nome.', 'frontendprofile');
	elseif ( !$userdata['last_name'] )
		$error = __('Desculpe, mas precisamos do seu sobrenome.', 'frontendprofile');
	
	else{
		$new_user = wp_insert_user( $userdata );
		wp_new_user_notification($new_user, $user_pass);
		update_usermeta( $new_user, 'birth',   esc_attr( $_POST['birth']    ) );
	}

}
	$moranguinho = 'sim';
	$logged = 'nao';
	$id='home';
	include 'header.php';


	$slideshow = get_id_by_post_name('slideshow-home');
	$slides = get_group('slide',$slideshow);
	$slidecount = count($slides);


	$destaque = get_id_by_post_name('destaques-home');
?>
			<div class="wrapper-content">
				<?php include 'login-panel.php'; ?>
				<span class="clear"></span>
				<div class="wrapper-slideshow">
					<div class="placa-slideshow">
						<img src="<?php bloginfo('template_directory')?>/img/placa-slideshow.png" alt=""/>
					</div>
					<div class="moranguinho-dog">
						<img src="<?php bloginfo('template_directory')?>/img/moranguinho-dog.png?4" alt=""/>
					</div>
					<div class="jcarousel">
						<ul>
							<?php for ($i=1; $i <= $slidecount ; $i++) { ?>
								<li><a href="<?php echo get('slide_link',$i,1,$slideshow); ?>"><img src="<?php echo get('slide_imagem',$i,1,$slideshow); ?>" alt=""/></a></li>
							<?php } ?>
						</ul>
					</div>
					<a href="#" class="jcarousel-control-prev">&lsaquo;</a>
					<a href="#" class="jcarousel-control-next">&rsaquo;</a>
					<span class="clear"></span>
					<a class="siga" href="#next">Next</a>
				</div>
				<span class="clear"></span>
				<div id="next" class="wrapper-seja-bff">
					<div class="seja-bff">
					<?php if ( $new_user ) : ?>

						<div class="alert">
							<p>
								<?php
									if ( current_user_can( 'create_users' ) )
										printf( __('Um usuário para %1$s foi criado.', 'frontendprofile'), $_POST['email'] );
									else 
										printf( __('Obrigado por se registrar, %1$s.', 'frontendprofile'), $_POST['first_name'] );
										printf( __('<br/>Por favor cheque seu e-mail. Enviamos uma senha para você.<br/> (Pode estar na pasta SPAM)', 'frontendprofile') );
								?>
							</p>
							<span class="close">X</span>
						</div><!-- .alert -->
					<?php endif; ?>
						<?php if ( $error ) : ?>
							<div class="error">
								<p><?php echo $error; ?></p>
								<span class="close">X</span>
							</div><!-- .error -->
						<?php endif; ?>
						<form class="form-seja-bff user-forms" action="http://<?php echo $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>" id="adduser" method="post">
							<div>
								<label for="nome">Nome *</label>
								<input type="text" name="first_name" id="first_name" />
							</div>
							<div>
								<label for="email">Email *</label>
								<input type="text" name="email" id="email" />
							</div>
							<div>
								<label for="sobrenome">Sobrenome *</label>
								<input type="text" name="last_name" id="last_name" />
							</div>
							<div>
								<label for="nascimento">Nascimento *</label>
								<input type="text" name="birth" id="birth" class="birth2" />
							</div>
							<span class="clear"></span>
							<input type="submit" value="Enviar" name="adduser"/>
							<?php wp_nonce_field( 'add-user' ) ?>
							<input name="action" type="hidden" id="action" value="adduser" />
						</form>
						<span class="clear"></span>
					</div><!-- /seja-bff -->
					<span class="clear"></span>
				</div><!-- /wrapper-seja-bff -->
				<span class="clear"></span>
				<div class="destaque-produtos">
					<?php include 'slide-produtos.php'; ?>
				</div><!-- /destaque-produtos -->
				<div class="wrapper-blog-home">
					<ul>
						<li>
							<div class="wrapper-img-blog">
								<a href="<?php echo get_permalink($destaque1); ?>"><?php $destaque1 = get('destaque_1_post',1,1,$destaque);
								echo get_the_post_thumbnail($destaque1,'destaque-home'); ?></a>
							</div>
							<div class="wrapper-info-blog">
								<div class="excerpt">
									<a href="<?php echo get_permalink($destaque1); ?>"><?php echo get_the_title($destaque1); ?></a>
								</div>
								<div class="info-post">
									<div class="author">
									<?php $author = get_post_field( 'post_author', $destaque1 ); ?>
										Posted by <?php the_author_meta( 'display_name', $author ); ?>
									</div>
									<div class="categories">
										Categories: <?php $category = get_the_category($destaque1); echo $category[0]->cat_name; ?>
									</div>
								</div>
								<div class="data-post">
									<?php echo get_the_time('j',$destaque1); ?> <span><?php echo substr(get_the_time('F',$destaque1),0,3); ?></span>
								</div>
								<span class="clear"></span>
								<span class="veja-mais-post">
									<a href="<?php echo get_permalink($destaque1); ?>">Veja Mais...</a>
								</span>
								<span class="clear"></span>
							</div>
							<span class="clear"></span>
						</li>
						<li>
							<div class="wrapper-img-blog">
								<a href="<?php echo get_permalink($destaque1); ?>"><?php $destaque1 = get('destaque_2_post',1,1,$destaque);
								echo get_the_post_thumbnail($destaque1,'destaque-home'); ?></a>
							</div>
							<div class="wrapper-info-blog">
								<div class="excerpt">
									<a href="<?php echo get_permalink($destaque1); ?>"><?php echo get_the_title($destaque1); ?></a>
								</div>
								<div class="info-post">
									<div class="author">
									<?php $author = get_post_field( 'post_author', $destaque1 ); ?>
										Posted by <?php the_author_meta( 'display_name', $author ); ?>
									</div>
									<div class="categories">
										Categories: <?php $category = get_the_category($destaque1); echo $category[0]->cat_name; ?>
									</div>
								</div>
								<div class="data-post">
									<?php echo get_the_time('j',$destaque1); ?> <span><?php echo substr(get_the_time('F',$destaque1),0,3); ?></span>
								</div>
								<span class="clear"></span>
								<span class="veja-mais-post">
									<a href="<?php echo get_permalink($destaque1); ?>">Veja Mais...</a>
								</span>
								<span class="clear"></span>
							</div>
							<span class="clear"></span>
						</li>
						<li class="no-margin">
							<div class="wrapper-img-blog">
								<a href="<?php echo get_permalink($destaque1); ?>"><?php $destaque1 = get('destaque_3_post',1,1,$destaque);
								echo get_the_post_thumbnail($destaque1,'destaque-home'); ?></a>
							</div>
							<div class="wrapper-info-blog">
								<div class="excerpt">
									<a href="<?php echo get_permalink($destaque1); ?>"><?php echo get_the_title($destaque1); ?></a>
								</div>
								<div class="info-post">
									<div class="author">
									<?php $author = get_post_field( 'post_author', $destaque1 ); ?>
										Posted by <?php the_author_meta( 'display_name', $author ); ?>
									</div>
									<div class="categories">
										Categories: <?php $category = get_the_category($destaque1); echo $category[0]->cat_name; ?>
									</div>
								</div>
								<div class="data-post">
									<?php echo get_the_time('j',$destaque1); ?> <span><?php echo substr(get_the_time('F',$destaque1),0,3); ?></span>
								</div>
								<span class="clear"></span>
								<span class="veja-mais-post">
									<a href="<?php echo get_permalink($destaque1); ?>">Veja Mais...</a>
								</span>
								<span class="clear"></span>
							</div>
							<span class="clear"></span>
						</li>
						<span class="clear"></span>
					</ul>
					<span class="clear"></span>
				</div><!-- /wrapper-blog-home -->
				<span class="clear"></span>
			</div><!-- /wrapper-content -->
			<span class="clear"></span>
		</div><!-- /container -->
		<span class="clear"></span>
	</div> <!-- /wrapper-container -->
	<span class="clear"></span>
<?php include 'footer.php'; ?>